
#include <e32cmn.h>
#include <w32std.h>
#include <gdi.h>
#include <coecntrl.h>
#include <euserhl.h>

#ifndef __DRAWUTILS__
#define __DRAWUTILS__

class MAnimation;

class CAnimator : public CTimer
	{
private:
	RArray<MAnimation*> iAnimations;
	TTime iStartTime, iCurrentTime;
	TInt iFrameRate;
	CCoeControl* iControl;
	void RunL();
public:
	void ConstructL(CCoeControl* aControl, TInt aFrameRate /* in frame per seconds */);
	TInt64 FrameTime(); // in microseconds
	const RArray<MAnimation*>& Animations() const;
	void AppendL(MAnimation* aAnimation);
	void StartL();
	void Stop();
	CAnimator();
	~CAnimator();
	};

class MAnimation
	{
	friend class CAnimator;
protected:
	CAnimator* iAnimator;
public:
	virtual TBool IsDoneL() const = 0;
	};

class TMarqueeAnimation : public MAnimation
	{
private:
	TInt iExcessWidth;
	TInt iSpeed; // in pixels per seconds
public:
	TMarqueeAnimation();
	void ResetL(const TDesC& aText, const CFont& aFont, const TInt aMargin, const TRect& aRect);
	TInt OffsetL();
	virtual TBool IsDoneL() const;
	};

void DrawTextExt(
		CWindowGc* aGc,
		const TRect& aRect, TSize aRoundedRectEllipse,
		const TDesC& aText, const CFont* aFont, const TRgb& aTextColor,
		CGraphicsContext::TTextAlign aTextAlign, TInt aTextMargin, TBool aCrop,
		const CGraphicsContext::TBrushStyle& aBackgroundBrushStyle, const TRgb& aBackgroundColor,
		const CGraphicsContext::TPenStyle& aBackgroundPenStyle, const TRgb& aBackgroundPenColor);


void DrawMarqueeText(
		CWindowGc* aGc, const CFont* aFont,
		const TDesC& aText,
		const TRect& aRect, 
		TInt aBaseline,
		CGraphicsContext::TTextAlign aTextAlign,
		TInt aMargin,
		const TTimeIntervalMicroSeconds& aFrameTime, TBool& aMarqueeCompleted);

void DrawMarqueeGeneric(
		CWindowGc* aGc, const CFont* aFont,
		TInt aWidth,
		const TRect& aRect, 
		TInt aBaseline,
		CGraphicsContext::TTextAlign aTextAlign,
		TInt aMargin,
		const TTimeIntervalMicroSeconds& aFrameTime,
		TInt& aOffset, TRect& aDrawRect, TBool& aMarqueeCompleted);


void SplitRectHorz(const TRect& aRect, TInt aWidth1, TRect& aCol1, TRect& aCol2);
void SplitRectHorz(const TRect& aRect, TInt aWidth1, TInt aWidth2, TRect& aCol1, TRect& aCol2, TRect& aCol3);
void SplitRectVert(const TRect& aRect, TInt aHeight1, TRect& aLine1, TRect& aLine2);
void SplitRectVert(const TRect& aRect, TInt aHeight1, TInt aHeight2, TRect& aLine1, TRect& aLine2, TRect& aLine3);
void ShrinkToSize(TRect& aRect, TInt aWidth, TInt aHeight);



struct CItemDrawerHelper : public CBase
	{
public:
	LManagedPtr<CAnimator> iAnimator;
	LManagedArray<TMarqueeAnimation> iMarqueeAnimation;
	TInt iLastCurrentItem, iItemIndex;
	TBool iItemIsCurrent;

	void ConstructL(CCoeControl* aControl, TInt aCount);
	void StartDrawItem(TInt aItemIndex, TInt aItemIsCurrent);
	void EndDrawItem();
	void DrawMarqueeItemPart(
			TInt aPartNumber,
			CWindowGc* aGc,
			const TRect& aRect, TSize aRoundedRectEllipse,
			const TDesC& aText, const CFont* aFont, const TRgb& aTextColor,
			CGraphicsContext::TTextAlign aTextAlign, TInt aTextMargin,
			const CGraphicsContext::TBrushStyle& aBackgroundBrushStyle, const TRgb& aBackgroundColor,
			const CGraphicsContext::TPenStyle& aBackgroundPenStyle, const TRgb& aBackgroundPenColor);
	};


#endif // __DRAWUTILS__
